//@Author: wulinlin
//@Description:
//@File:  file_service
//@Version: 1.0.0
//@Date: 2024/04/22 21:20

package service

import (
	"context"
	"ebip/internel/domain"
	"errors"
	"os"
)

type FileService interface {
	GetFileInfo(ctx context.Context, path string) (domain.FileSchemaDM, error)
}

func NewFileService() FileService {
	return &fileService{}
}

type fileService struct {
}

func (f *fileService) GetFileInfo(ctx context.Context, path string) (domain.FileSchemaDM, error) {
	fileInfo, err := os.Stat(path)
	if os.IsNotExist(err) {
		return domain.FileSchemaDM{}, errors.New("文件路径不存在")
	}
	if err != nil {
		return domain.FileSchemaDM{}, errors.New("系统错误，校验文件错误")
	}
	var fileSchema = domain.FileSchemaDM{
		FileName: "",
		FileSize: float64(fileInfo.Size()) / 1024 / 1024, // 获取文件大小
	}
	return fileSchema, nil
}
